package org.qpcr.community.device.enums;

import lombok.Getter;
import org.hswebframework.web.exception.BusinessException;

import java.util.Arrays;

public enum CalibrationCommandTypeEnums {
    // 校准相关命令
    CALIBRATION("calibration", "温度校准","触发设备校准流程，返回校准后的温度/荧光等核心指标"),
    TEST("test", "测试","执行设备精度测试，返回测试结果（与校准结果格式一致，用于验证设备状态）"),
    WRITE_PARAM("writeParam", "写入参数","向设备写入校准参数（如温度补偿值、荧光通道增益等），返回写入结果"),
    BACKTRACK_PARAM("backtrackParam", "回溯参数","回溯设备历史校准参数（如最近3次校准的参数记录），返回历史参数列表"),
    TERMINATE_RUN("terminateRun", "终止运行", "终止设备当前正在执行的校准/测试流程，返回终止时的状态信息"),
    GET_INITIAL_VALUE("getInitialValue", "获取初始值", "获取设备出厂初始校准值（与校准结果格式一致，用于对比校准前后差异）"),
    GET_CALIBRATION_BEFORE_PARAM("getCalibrationBeforeParam", "获取校准前参数", "获取校准前参数"),

    // 荧光校准相关命令
    FLUORESCENCE_WRITE_PARAM("fluorescenceWriteParam", "荧光校准写入参数", "荧光校准写入参数"),
    FLUORESCENCE_BACKTRACK_PARAM("fluorescenceBacktrackParam", "荧光校准回溯参数", "荧光校准回溯参数"),

    // 工装验证和盖板控制命令
    VERIFY_FIXTURE("verifyFixture", "校准工装是否存在", "验证校准工装是否存在"),
    GET_COVER_STATUS("getCoverStatus", "查询盖板状态", "查询盖板状态"),
    OPEN_COVER("openCover", "打开盖板", "打开盖板"),
    OPEN_COVER_FORCE("openCoverForce", "强制打开盖板", "强制打开盖板"),
    CLOSE_COVER("closeCover", "关闭盖板", "关闭盖板"),

    // 数据导出命令
    EXPORT_DETAIL_DATA("exportDetailData", "导出详细数据查询", "导出详细数据查询"),

    // 压头力矩控制命令
    SET_PRESS_HEAD_TORQUE("setPressHeadTorque", "设置压头力矩", "设置压头力矩"),
    GET_PRESS_HEAD_TORQUE("getPressHeadTorque", "查询当前压头力矩", "查询当前压头力矩"),

    // 气泵气压控制命令
    SET_AIR_PUMP_PRESSURE("setAirPumpPressure", "设置气泵气压", "设置气泵气压"),
    GET_AIR_PUMP_PRESSURE("getAirPumpPressure", "查询当前气泵气压", "查询当前气泵气压"),

    // 数据上传频率控制命令
    SET_UPLOAD_FREQUENCY("setUploadFrequency", "设置数据上传频率", "设置数据上传频率"),
    GET_UPLOAD_FREQUENCY("getUploadFrequency", "查询当前数据上传频率", "查询当前数据上传频率"),

    // 保留原有的一些枚举值（如果仍需要的话）
    FLUORESCENCE_CALIBRATION_PROCESS("fluorescenceCalibrationProcess", "荧光校准数据处理", "荧光校准数据处理"),
    PARAMETER_ANALYSIS("parameterAnalysis", "参数分析", "参数分析"),
    FLUORESCENCE_TERMINATE_RUN("fluorescenceTerminateRun", "荧光校准终止运行", "荧光校准终止运行"),
    GET_PRESS_HEAD_TORQUE_STATUS("getPressHeadTorqueStatus", "查询压头开关状态", "查询压头开关状态"),
    OPEN_PRESS_HEAD_TORQUE("openPressHeadTorque", "打开压头开关", "打开压头开关"),
    CLOSE_PRESS_HEAD_TORQUE("closePressHeadTorque", "关闭压头开关", "关闭压头开关"),
    GET_AIR_PUMP_PRESSURE_STATUS("getAirPumpPressureStatus", "查询气泵开关状态", "查询气泵开关状态"),
    OPEN_AIR_PUMP_PRESSURE("openAirPumpPressure", "打开气泵开关", "打开气泵开关"),
    CLOSE_AIR_PUMP_PRESSURE("closeAirPumpPressure", "关闭气泵开关", "关闭气泵开关"),
    ;

    @Getter
    private final String type;
    @Getter
    private final String typeName;
    @Getter
    private final String desc;

    CalibrationCommandTypeEnums(String type, String desc, String typeName) {
        this.type = type;
        this.desc = desc;
        this.typeName = typeName;
    }

    public static Boolean validateType(String type) {
        for (CalibrationCommandTypeEnums value : CalibrationCommandTypeEnums.values()) {
            if (value.getType().equals(type)) {
                return true;
            }
        }
        return false;
    }

    public static CalibrationCommandTypeEnums getByType(String type) {
        for (CalibrationCommandTypeEnums value : CalibrationCommandTypeEnums.values()) {
            if (value.getType().equals(type)) {
                return value;
            }
        }
        throw new BusinessException("未知的校准命令类型");
    }


    public static Boolean isTemperatureCalibration(String type) {
        return type.equals(CALIBRATION.getType());
    }
}
